<template>
    <el-menu router class="el-menu-vertical-demo" 
        background-color="#545c64" text-color="#fff" :default-active="$route.path" active-text-color="#ffd04b"  @select="chooseMenu">
        <el-submenu :index="first.id" v-for="first in listMenu">
            <template slot="title">
                <i :class="first.icon"></i>
                <span>{{first.name}}</span>
            </template>
            <el-menu-item :index="second.url" v-for="second in first.children">{{second.name}}</el-menu-item>
        </el-submenu>
        <!-- <el-submenu index="sys">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>系统管理</span>
            </template>
            <el-menu-item index="/layout/def">字典管理</el-menu-item>
            <el-menu-item index="/layout/sqlTemplate">查询模板</el-menu-item>
            <el-menu-item index="/layout/accountBook">帐套管理</el-menu-item>
            <el-menu-item index="/layout/admin">管理员管理</el-menu-item>
            <el-menu-item index="/layout/org">组织管理</el-menu-item>
            <el-menu-item index="/layout/role">角色管理</el-menu-item>
            <el-menu-item index="/layout/permission">菜单管理</el-menu-item>
        </el-submenu>
        <el-submenu index="yunwei">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>运维配置</span>
            </template>
            <el-menu-item index="/layout/swiper">轮播图管理</el-menu-item>
            <el-menu-item index="/layout/protocol">平台协议</el-menu-item>
            <el-menu-item index="/layout/notice">平台公告</el-menu-item>
            <el-menu-item index="/layout/servicetype">服务类目</el-menu-item>
            <el-menu-item index="/layout/infotype">资讯栏目</el-menu-item>
        </el-submenu>
        <el-submenu index="ums">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>用户管理</span>
            </template>
            <el-menu-item index="/layout/user">平台用户</el-menu-item>
            <el-menu-item index="/layout/dsuser">待审核用户</el-menu-item>
        </el-submenu>
        <el-submenu index="business">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>商家管理</span>
            </template>
            <el-menu-item index="/layout/hxorg">商家管理</el-menu-item>
            <el-menu-item index="/layout/dshxorg">入驻商家审核</el-menu-item>
            <el-menu-item index="/layout/hxproduct">商品管理</el-menu-item>
        </el-submenu>
        <el-submenu index="info_product">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>商品管理</span>
            </template>
            <el-menu-item index="/layout/esproduct">二手交易商品</el-menu-item>
            <el-menu-item index="/layout/xhproduct">现货商品</el-menu-item>
        </el-submenu>
        <el-submenu index="oms">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>订单管理</span>
            </template>
            <el-menu-item index="/layout/hxmborder">会员购买订单</el-menu-item>
            <el-menu-item index="/layout/hxorder">商品订单</el-menu-item>
            <el-menu-item index="/layout/hxdrawalbill">提现申请单</el-menu-item>
        </el-submenu>
        <el-submenu index="meeting">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>会议活动</span>
            </template>
            <el-menu-item index="/layout/hxmeeting">会议活动</el-menu-item>
        </el-submenu>
        <el-submenu index="oms_drawal">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>求购定制</span>
            </template>
            <el-menu-item index="/layout/hxdrawalbill">求购报价</el-menu-item>
            <el-menu-item index="/layout/customservice">定制服务</el-menu-item>
        </el-submenu>
        <el-submenu index="wiki">
            <template slot="title">
                <i class="el-icon-location"></i>
                <span>科普资讯</span>
            </template>
            <el-menu-item index="/layout/hxwiki">有机科普</el-menu-item>
            <el-menu-item index="/layout/coffeproduct">化学资讯</el-menu-item>
        </el-submenu> -->
    </el-menu>
</template>

<script>
export default {
    data() {
        return {
            listMenu: [],
            secondMenu: []
        }
    },
    created() {
        this.listMenu = this.$session.getUserMenu();
        for (let first of this.listMenu) {
            this.secondMenu.push(...first.children);
        }
    },
    methods: {
        chooseMenu(index, indexPath) {
            let menu = this.secondMenu.find(item => item.url == index);
            this.$store.commit("menu/ADD_TAB", {
                name: menu.name, 
                url: menu.url, 
                closeable: true, 
                id: menu.id
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.el-menu {
    border-right: 0px;
}
</style>